import request from '../../utils/request';

/**
 * 获取所有组件数据
 */
export function fetch(pageId) {
    return request(`${is.CONST.urls.widgets}?page_id=${pageId}`);
}

/**
 * 创建单个组件
 */
export function create(pageId, widget) {
    return request(`${is.CONST.urls.widgets}?page_id=${pageId}`, {
        method: 'POST',
        body: JSON.stringify(widget),
    });
}

/**
 * 更新单个组件信息
 */
export function updateOne(widget) {
    return request(is.CONST.urls.widgets, {
        method: 'PUT',
        body: JSON.stringify(widget),
    });
}

/**
 * 删除单个组件
 */
export function remove(pageId, widgetId) {
    return request(`${is.CONST.urls.widgets}?page_id=${pageId}&id=${widgetId}`, {
        method: 'DELETE',
    });
}
